package com.dkts.oil.router.thread;

import com.dkts.oil.router.param.RouterInfo;
import com.dkts.oil.web.vo.request.RouteCommonRequest;

import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer;

public abstract class RouteLycToZyTask implements Runnable {
    protected final RouteCommonRequest param;
    protected final String url;
    protected final Consumer<RouterInfo> callback;
    protected final CountDownLatch latch;
    protected final String profile;

    protected RouteLycToZyTask(RouteCommonRequest param, String url, Consumer<RouterInfo> callback, CountDownLatch latch,String  profile) {
        this.param = param;
        this.url = url;
        this.callback = callback;
        this.latch = latch;
        this.profile = profile;
    }

    protected abstract RouterInfo getRouterAll();

    @Override
    public void run() {
        try {
            RouterInfo result = this.getRouterAll();
            callback.accept(result);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            latch.countDown();
        }
    }
}
